package org.example.sword2offer.primary;

/**
 * @author: lynn
 * @Descript:求根号3，保留后8位
 * @date: 2021/4/9 22:45
 * @version: 1.0
 */
public class Q64_1_Radical3 {
    private static double r;
    public static void main(String[] args) {
        System.out.println(sqrt(3.0));
    }

    public static double sqrt(double number) {
      return process(number, 0, number);
    }

    private static double process(double number, double min, double max) {
        double mid = min + (max - min) / 2;
        double result = mid * mid;

        //设置精度为0.001
        if (Math.abs(result - number) <= 0.01) {
            r = mid;
            return r;
        }
        if (result > number) {
            max = mid;
        } else {
            min = mid;
        }
        //递归调用
       return process(number, min, max);
    }
}
